home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Python 1.4 / Python 1.4 source / Lib / tkinter / ScrolledText.py < prev    next >
Encoding:
Python Source  |  1996-08-02  |  1.2 KB  |  36 lines  |  [TEXT/Pyth]

  1. # A ScrolledText widget feels like a text widget but also has a
  2. # vertical scroll bar on its right.  (Later, options may be added to
  3. # add a horizontal bar as well, to make the bars disappear
  4. # automatically when not needed, to move them to the other side of the
  5. # window, etc.)
  6. #
  7. # Configuration options are passed to the Text widget.
  8. # A Frame widget is inserted between the master and the text, to hold
  9. # the Scrollbar widget.
  10. # Most methods calls are inherited from the Text widget; Pack methods
  11. # are redirected to the Frame widget however.
  12.  
  13. from Tkinter import *
  14. from Tkinter import _cnfmerge
  15.  
  16. class ScrolledText(Text):
  17.     def __init__(self, master=None, **cnf):
  18.         fcnf = {}
  19.         for k in cnf.keys():
  20.             if type(k) == ClassType or k == 'name':
  21.                 fcnf[k] = cnf[k]
  22.                 del cnf[k]
  23.         self.frame = apply(Frame, (master,), fcnf)
  24.         self.vbar = Scrollbar(self.frame, name='vbar')
  25.         self.vbar.pack(side=RIGHT, fill=Y)
  26.         cnf['name'] = 'text'
  27.         apply(Text.__init__, (self, self.frame), cnf)
  28.         self.pack(side=LEFT, fill=BOTH, expand=1)
  29.         self['yscrollcommand'] = self.vbar.set
  30.         self.vbar['command'] = self.yview
  31.  
  32.         # Copy Pack methods of self.frame -- hack!
  33.         for m in Pack.__dict__.keys():
  34.             if m[0] != '_' and m != 'config':
  35.                 setattr(self, m, getattr(self.frame, m))
  36.